package com.bd.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Named;

import com.bd.controller.ControllerImpl;
import com.bd.model.Label;

@Named
@FacesConverter(forClass = Label.class)
public class LabelConverter implements Converter {

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object valueToRender) {
		return ((Label) valueToRender).toString();
	}

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
		ControllerImpl ctrl = (ControllerImpl) context.getApplication().getELResolver().getValue(context.getELContext(), null, "controllerImpl");
		return (Label) ctrl.findLabelByName(submittedValue);
	}

}